package com.cardone.platform.configuration.controller;

import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cardone.context.Contexts;
import com.cardone.common.dto.PaginationDto;
import com.cardone.common.util.ReturnDataUtils;
import com.cardone.context.ContextHolder;
import com.cardone.platform.configuration.dto.SiteDto;
import com.cardone.platform.configuration.service.SiteService;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
* 站点
*
* @author yaohaitao
*/
@Setter
@Slf4j
@Controller
public class SiteController {
/**
* 站点：删除
*
* @param deleteSite
*            站点对象
* @return 处理结果，json格式
*/
@Deprecated
@RequestMapping(value = { "/configuration/site/delete.json" }, method = RequestMethod.POST)
@ResponseBody
public Callable<Map<String, Object>> deleteJson(final SiteDto deleteSite) {
    return () -> {
    ContextHolder.getBean(SiteService.class).deleteByIds(deleteSite);

    return ReturnDataUtils.newMap();
    };
    }

    /**
    * 站点：编辑
    *
    * @param findSite
    *            站点对象
    * @return 实体对象集，json格式
    */
    @Deprecated
    @RequestMapping(value = { "/configuration/site/findById.json" })
    @ResponseBody
    public Callable<Map<String, Object>> findByIdJson(final SiteDto findSite, final Model model) {
    return () -> {
    final SiteDto site = ContextHolder.getBean(Site
    Service.class).findById(SiteDto.class, findSite);

    return ReturnDataUtils.newMap("site", site);
    };
    }

    /**
    * 站点：分页查询
    *
    * @param paginationSite
    *            站点对象
    * @return 分页，json格式
    */
    @Deprecated
    @RequestMapping(value = { "/configuration/site/paginationByLikeCode.json" })
    @ResponseBody
    public Callable<Map<String, Object>> paginationByLikeCodeJson(final SiteDto paginationSite) {
    return () -> {
    final PaginationDto
<SiteDto> sitePagination = ContextHolder.getBean(Site
    Service.class).paginationByLikeCode(SiteDto.class, paginationSite);

    return ReturnDataUtils.newMap("sitePagination", sitePagination);
    };
    }

    /**
    * 站点：分页查询
    *
    * @param paginationSite
    *            站点对象
    * @param model
    *            上下文映射
    */
    @Deprecated
    @RequestMapping(value = { "/configuration/site/pagination.html" })
    public void paginationHtml(final SiteDto paginationSite, final Model model) {
    final PaginationDto
<SiteDto> sitePagination = ContextHolder.getBean(Site
    Service.class).paginationByLikeCode(SiteDto.class, paginationSite);

    model.addAttribute("sitePagination", sitePagination);
    }

    /**
    * 站点：分页查询
    *
    * @param findSite
    *            站点对象
    * @param model
    *            上下文映射
    */
    @Deprecated
    @RequestMapping(value = { "/configuration/site/edit.html" })
    public void editHtml(final SiteDto findSite, final Model model) {
    final SiteDto site = ContextHolder.getBean(Site
    Service.class).findById(SiteDto.class, findSite);

    model.addAttribute("site", site);
    }

    /**
    * 站点：查询
    *
    * @param findListSite
    *            站点对象
    * @return 站点对象集合，json格式
    */
    @Deprecated
    @RequestMapping(value = { "/configuration/site/findListByLikeCode.json" })
    @ResponseBody
    public Callable<Map<String, Object>> findListByLikeCodeJson(final SiteDto findListSite) {
    return () -> {
    final List<SiteDto> siteList = ContextHolder.getBean(Site
    Service.class).findListByLikeCode(SiteDto.class, findListSite);

    return ReturnDataUtils.newMap("site", siteList);
    };
    }

    /**
    * 站点：保存
    *
    * @param saveSite
    *            站点对象
    * @return 处理结果，json格式
    */
    @Deprecated
    @RequestMapping(value = { "/configuration/site/save.json" })
    @ResponseBody
    public Callable<Map<String, Object>> saveJson(final SiteDto saveSite) {
    return () -> {
    ContextHolder.getBean(SiteService.class).saveByIdOrCode(SiteDto.class, saveSite);

    return ReturnDataUtils.newMap();
    };
    }
    }
